package day18.feifei;

public class Demo_Join implements Runnable{
    @Override
    public void run() {
        System.out.println("线程开始：" + Thread.currentThread().getName());
        try {
            Thread.sleep(2000); // 模拟一些任务
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("线程结束：" + Thread.currentThread().getName());
        for(int i=0;i<100;i++){
            System.out.println( Thread.currentThread().getName()+"-----"+i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new Demo_Join());
        Thread thread2 = new Thread(new Demo_Join());
        thread1.start();
        thread2.start();

            thread1.join(); // 等待 thread1 完成
            thread2.join(); // 等待 thread2 完成

        System.out.println("主线程结束");
    }
}

